
package com.sunriz.javafx.views;

import com.sunriz.javafx.MainApplication;
import com.sunriz.javafx.server.driver.OpenocdManager;
import com.sunriz.javafx.server.driver.RttClient;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

import java.io.IOException;

public class SecondViewController {
    @FXML
    private Label message;

    public void hello(){
        message.setText("welcome to secondView");
        OpenocdManager openocdManager = OpenocdManager.getInstance();
        RttClient rttClient = RttClient.getInstance();

        try {
            openocdManager.start();
            Thread.sleep(2000);
            rttClient.start();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    // 处理 "Back" 按钮点击事件
    public void goBack(ActionEvent event) throws IOException {

        OpenocdManager openocdManager = OpenocdManager.getInstance();
        RttClient rttClient = RttClient.getInstance();

        rttClient.close();
        openocdManager.close();

        FXMLLoader loader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml"));
        Scene scene = new Scene(loader.load(), 800, 600);
        // 获取当前窗口
        Stage currentStage = (Stage) message.getScene().getWindow();

        currentStage.setScene(scene);
        currentStage.show();
    }
}
